package com.dz.xjd.params;

import com.alibaba.fastjson.JSON;
import com.dz.xjd.app.App;
import com.dz.xjd.app.Constant;
import com.dz.xjd.bean.HeaderParams;
import com.dz.xjd.bean.LoginParams;
import com.dz.xjd.bean.MsmParams;
import com.dz.xjd.bean.ProfessionParams;
import com.dz.xjd.utils.EncryptDecrypt;
import com.dz.xjd.utils.KeyUtil;
import com.orhanobut.logger.Logger;

/**
 * Created by dz on 2017/7/29.
 */

public class Params {

    public static String tokenHeadParams(){
        HeaderParams headerParams = new HeaderParams();
        headerParams.setOsversion("2.0");
        headerParams.setDeviceToken("1234567890");
        headerParams.setFrom("android");
        headerParams.setMethod(Constant.METHOD_TOKEN);
        headerParams.setCurrentDevice("iphone 7");
        headerParams.setToken("");
        String header = JSON.toJSONString(headerParams);
        return header;
    }


    public static String normalHeadParams(String method){
        HeaderParams headerParams = new HeaderParams();
        headerParams.setOsversion("2.0");
        headerParams.setDeviceToken("1234567890");
        headerParams.setFrom("android");
        headerParams.setMethod(method);
        headerParams.setCurrentDevice("iphone 7");
        headerParams.setToken(App.getToken());
        String header = JSON.toJSONString(headerParams);
        return header;
    }

    public static String msmParams(String username){
        MsmParams mMsmParams = new MsmParams();
        mMsmParams.setUser_id(0);
        mMsmParams.setPhone(username);
        mMsmParams.setType(0);
        String strParams = JSON.toJSONString(mMsmParams);
        String[] keys = KeyUtil.getKey(App.getToken());
        Logger.d(strParams);
        String encryptParams = "";
        try {
            encryptParams = EncryptDecrypt.encrypt(keys[0], strParams, keys[1]);
            Logger.d(strParams);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return encryptParams;
    }

    public static String loginParams(String username, String validate){
        LoginParams loginParams = new LoginParams();
        loginParams.setUser_id(0);
        loginParams.setPhone(username);
        loginParams.setCode(validate);

        String strParams = JSON.toJSONString(loginParams);
        Logger.d(strParams);
        String[] keys = KeyUtil.getKey(App.getToken());
        String encryptParams = "";
        try {
            encryptParams = EncryptDecrypt.encrypt(keys[0], strParams, keys[1]);
            Logger.d(encryptParams);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return encryptParams;
    }

    public static String professionParams(){
        ProfessionParams profession = new ProfessionParams();
        profession.setUser_id(App.mUserBean.getUser_id());
        profession.setType("all");
        String strParams = JSON.toJSONString(profession);
        Logger.d(strParams);
        String[] keys = KeyUtil.getKey(App.getToken());
        String encryptParams = "";
        try {
            encryptParams = EncryptDecrypt.encrypt(keys[0], strParams, keys[1]);
            Logger.d(encryptParams);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return encryptParams;
    }
}
